package com.fuqi.android.zhongcai.base.view.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.ApiUrl;
import com.fuqi.android.zhongcai.base.request.result.SanBaoResult;
import com.fuqi.android.zhongcai.utils.LogUtils;

import java.util.List;

/**
 * create by juner
 * @Date 2016-8-31
 */


public class SanBaoAdapter extends BaseRecyclerViewAdapter<SanBaoResult>{
    private Context context;

    public SanBaoAdapter(Context context, List<SanBaoResult> datas) {
        super(datas);
        this.context = context;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.adapter_san_bao;
    }

    @Override
    protected void onBind(final ViewHolder holder, int position,SanBaoResult data) {
        holder.setTextView(R.id.item_tv_title, data.getTitle());
        holder.setTextView(R.id.item_tv_time, "08-09");

        Glide.with(context.getApplicationContext())
                .load(ApiUrl.getDefaultHost() + data.getPicPth())
                .asBitmap()
                .centerCrop()
                .placeholder(R.mipmap.san_bao_bg_header)
                .into(new BitmapImageViewTarget((ImageView) holder.get(R.id.item_img)) {
                    @Override
                    protected void setResource(Bitmap resource) {
                        RoundedBitmapDrawable roundedBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(context.getResources(), resource);
//                roundedBitmapDrawable.setCircular(true);
                        roundedBitmapDrawable.setCornerRadius(20); //设置圆角半径（根据实际需求）
                        roundedBitmapDrawable.setAntiAlias(true); //设置反走样
                        ((ImageView) holder.get(R.id.item_img)).setImageDrawable(roundedBitmapDrawable);
                    }
                });
        LogUtils.i("pic_path " + (ApiUrl.getDefaultHost() + data.getPicPth()));
    }
}
